{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__Вопросы для повторения__:\n",
    "* какие контейнеры-последовательности вы помните? Какова их внутренняя организация?\n",
    "\n",
    "<details>\n",
    "<summary>Подсказка</summary>\n",
    "<p>\n",
    "\n",
    "`array, valarray, vector, deque, list, forward_list`\n",
    "\n",
    "</p>\n",
    "</details>\n",
    "\n",
    "* какие ассоциативные контейнеры вы помните? Какова их внутренняя организация?\n",
    "\n",
    "<details>\n",
    "<summary>Подсказка</summary>\n",
    "<p>\n",
    "    \n",
    "`set, map , unordered_set, unordered_map`\n",
    "    \n",
    "</p>\n",
    "</details>\n",
    "\n",
    "* в чём здесь проблема?\n",
    "\n",
    "```c++\n",
    "std::vector<int> v;\n",
    "for (int i = 0; i < 1024; ++i)\n",
    "    if (i % 2 == 0)\n",
    "        v.push_back(i);\n",
    "```\n",
    "\n",
    "<details>\n",
    "<summary>Подсказка</summary>\n",
    "<p>\n",
    "\n",
    "`reserve` + лишний `%`\n",
    "\n",
    "</p>\n",
    "</details>\n",
    "\n",
    "* а здесь?\n",
    "\n",
    "```c++\n",
    "void run_to_erebor(const std::set<std::string>& dwarfs)\n",
    "{\n",
    "    // we need exactly std::vector here\n",
    "    std::vector<std::string> team;\n",
    "    for (const auto& dwarf : dwarfs)\n",
    "        team.emplace_back(dwarf);\n",
    "    ...\n",
    "}\n",
    "```\n",
    "\n",
    "<details>\n",
    "<summary>Подсказка</summary>\n",
    "<p>\n",
    "    \n",
    "обратить внимание что делает `emplace_back` и для чего вообще существует семейство `emplace`-методов\n",
    "\n",
    "```c++\n",
    "void run_to_erebor(const std::set<std::string>& dwarfs)\n",
    "{\n",
    "    // we need exactly std::vector here\n",
    "    std::vector<std::string> team{dwarfs.begin(), dwarfs.end()};    \n",
    "    ...\n",
    "}\n",
    "```\n",
    "\n",
    "</p>\n",
    "</details>\n",
    "\n",
    "* здесь?\n",
    "\n",
    "```c++\n",
    "std::vector<std::string> team = ...;\n",
    "for (auto it = team.begin(); it <= team.end(); ++it)\n",
    "    std::cout << *it << std::endl;\n",
    "```\n",
    "\n",
    "<details>\n",
    "<summary>Подсказка</summary>\n",
    "<p>\n",
    "    \n",
    "разыменование end\n",
    "\n",
    "</p>\n",
    "</details>\n",
    "\n",
    "* сколько здесь аллокаций? какие?\n",
    "\n",
    "```c++\n",
    "std::deque<std::string> team;\n",
    "for (int i = 0; i < N; ++i)\n",
    "    team.emplace_back(\"imperial storm trooper\");\n",
    "```\n",
    "\n",
    "<details>\n",
    "<summary>Подсказка</summary>\n",
    "<p>\n",
    "\n",
    "`N` аллокаций на конструирование строк, `N / размер блока` аллокаций под блоки дека + аллокации на таблицу блоков в деке.\n",
    "\n",
    "</p>\n",
    "</details>\n",
    "\n",
    "* что будет выведено здесь?\n",
    "\n",
    "```c++\n",
    "std::vector<int> v = {10, 20, 30, 40, 50};\n",
    "\n",
    "auto it1 = v.begin();\n",
    "auto it2 = std::next(it1);\n",
    "auto it3 = std::next(it2);\n",
    "auto it4 = std::next(it3);\n",
    "\n",
    "v.insert(it3, 25);\n",
    "\n",
    "std::cout << *it1 << std::endl;\n",
    "std::cout << *it2 << std::endl;\n",
    "std::cout << *it3 << std::endl;\n",
    "std::cout << *it4 << std::endl;\n",
    "```\n",
    "\n",
    "<details>\n",
    "<summary>Подсказка</summary>\n",
    "<p>\n",
    "\n",
    "Все итераторы после вставки инвалидированы, разыменование инвалидированых итераторов - ub.\n",
    "\n",
    "</p>\n",
    "</details>\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
